var fs=require('fs');
var http=require('http');
var url=require('url');
var assets='./assets';

var server=http.createServer(function (req, res) {
    var urlObj=url.parse(req.url);
    var path=urlObj.pathname;

    fs.stat(assets+path,function (err, stat) {
        if(err){

            if('ENOENT' == err.code){
                res.statusCode=404;
                res.end('Not Found.');
            }else{
                res.statusCode=500;
                res.end('Internal Server Error.');
            }
        }else{
            var stream=fs.createReadStream(assets+path);
            stream.pipe(res);
            stream.on('error',function (err) {
                res.statusCode=500;
                res.end('Internal Server Error.');
            });
        }
    });
});
server.listen(3000,function () {
  console.log('Staic server port:3000',new Date());  
});
